Nonterminals templ text_ stmt expr tokens token.

Terminals 'text' 'l_delim' 'r_delim' 
		  'if' 'let' '=' 'foreach' 'in' 'else'
		  'end' 'endif' 'endlet' 'endforeach'
		  'include'

		  'boolean' 'integer' 'string' 'name' 
		  '.' '[' ']' '(' ')' ',' ':'
		  '==' '!=' '<' '<=' '>' '>=' '&&' '||' '!'
		  '+' '-' '*' '/'.


Rootsymbol templ.

templ -> text_ :			''.
templ -> text_ l_delim r_delim templ : ''.
templ -> text_ l_delim stmt r_delim templ : ''.

text_ -> text :		  		templ_parse_handler:text(value_of('$1')).

stmt -> if expr:			templ_parse_handler:start_if('$2').
stmt -> let 'name' '=' expr:
							templ_parse_handler:start_let('$2', '$4').
stmt -> foreach name in expr: 
		   	   	   	   	   	templ_parse_handler:start_foreach('$2', '$4').
stmt -> else :				templ_parse_handler:else().
stmt -> end :				templ_parse_handler:end_stmt().
stmt -> endif :				templ_parse_handler:end_if().
stmt -> endlet :			templ_parse_handler:end_let().
stmt -> endforeach :		templ_parse_handler:end_foreach().
stmt -> expr :				templ_parse_handler:expr('$1').
stmt -> include string:		include(value_of('$2')).

%expr -> tokens :			{expr, '$1'}.
expr -> tokens :			{expr, templel_parse('$1')}.

tokens -> token :			['$1'].
tokens -> token tokens :	['$1'|'$2'].

token -> 'boolean' :   		'$1'.
token -> 'integer' :   		'$1'.
token -> 'string' :   		'$1'.
token -> 'name' :   		'$1'.
token -> '.' :   			'$1'.
token -> '[' :   			'$1'.
token -> ']' :   			'$1'.
token -> '(' :   			'$1'.
token -> ')' :   			'$1'.
token -> ',' :   			'$1'.
token -> '==' :   			'$1'.
token -> '!=' :   			'$1'.
token -> '<' :   			'$1'.
token -> '<=' :   			'$1'.
token -> '>' :   			'$1'.
token -> '>=' :   			'$1'.
token -> '&&' :   			'$1'.
token -> '||' :   			'$1'.
token -> '!' :   			'$1'.
token -> ':' :   			'$1'.
token -> '+' :   			'$1'.
token -> '-' :   			'$1'.
token -> '*' :   			'$1'.
token -> '/' :   			'$1'.


Erlang code.
value_of(Token) ->
	element(3, Token).

templel_parse(Tokens) ->
    case templel_parser:parse(Tokens) of
		{ok,Val}    ->
			Val;
		{error,Why} ->
			throw({{templ_parser,einval}, Why})
	end.

include(File) ->
	Templ = templ:read_file(File),
	case parse(templ_scan:string(Templ) ++ [{'$end',999}]) of
		{ok,Val}    ->
			Val;
		{error,Why} ->
			throw({{templ_parser,einval}, Why})
	end.
